
requirejs.config({
    baseUrl: '/js',
});


requirejs(['engine/doll.js']);

function fill_scene() {

}

function add_stats() {
    stats = new Stats();
    stats.setMode(0); // 0: fps, 1: ms

    // Align top-left
    stats.domElement.style.position = 'absolute';
    stats.domElement.style.left = '0px';
    stats.domElement.style.top = '0px';
    document.body.appendChild( stats.domElement );
}


function init() {
    clock = new THREE.Clock();
    scene = new THREE.Scene();
    //first 75 or 45?
    //last 1000 or 80000?
    camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 80000 );
    camera.position.set(0, 0, 20);
    renderer = new THREE.WebGLRenderer( {antialias: true} );

    renderer.gammaInput = true;
    renderer.gammaOutput = true;
    renderer.setClearColor(0xaaaaaa,1.0);
    renderer.setSize( window.innerWidth, window.innerHeight );

    //init engine
    doll.ui.init();
    doll.text.init();
    doll.fetch.init();
    doll.audio.init();
    doll.camera = camera;//current camera global
    doll.scene = scene; //current scene global
    doll.window_width = window.innerWidth;
    doll.window_height = window.innerHeight;

    document.body.appendChild( renderer.domElement );
}


function setup_audio() {
    //loads from assets/audio
    var audio = [
//        'ponponpon.wav',
//        'oniichan_09.ogg'
    ];
    doll.audio.complete = function() {
        console.log('hey I got all my audio');
        //doll.audio.play(1);
    }
    doll.audio.fetch(audio, false);
}


function animate() {
    requestAnimationFrame(animate, renderer.domElement);
    render();
}

function render() {
    setInterval( function () {
        console.profile('render');
        stats.begin();
    
        var delta = clock.getDelta();

        doll.ui.animate(delta);
        renderer.render(scene, camera);
        stats.end();
        console.profileEnd('render');
    }, 1000/60);
}

init();
setup_audio();
fill_scene();
add_stats();
animate();


